package com.nsgf.library.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import androidx.databinding.DataBindingUtil;

import com.nsgf.library.R;
import com.nsgf.library.databinding.DialogHomeUserSignDataBinding;
import com.nsgf.library.databinding.LayoutSpinnerPopupBinding;

public class SpinnerPopupWindow {

    private PopupWindow popupWindow;
    private View anchorView;

    public LayoutSpinnerPopupBinding binding;
    public SpinnerPopupWindow(Context context, View anchorView) {
        this.anchorView = anchorView;
        // 加载布局文件
        View popupView = LayoutInflater.from(context).inflate(R.layout.layout_spinner_popup, null);

        binding = DataBindingUtil.bind(popupView);
        // 创建PopupWindow实例
        popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        // 设置PopupWindow可以获得焦点，否则无法响应点击事件
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        // 显示下拉弹窗
        popupWindow.showAsDropDown(anchorView, 0, 0);
    }

}